var express = require('express');
var router = express.Router();
let { Xiangmodel, Renmodel } = require('../db/model.js')
/* GET home page. */
router.post('/addtype', function (req, res, next) {
	Xiangmodel.create(req.body).then(rep => {
		res.send({
			msg:'添加成功',
			code:200
		})
	})
});
router.post('/addren', function (req, res, next) {
	Renmodel.create(req.body).then(rep => {
		res.send({
			msg:'添加成功',
			code:200
		})
	})
});
router.get('/type', function (req, res, next) {
	Xiangmodel.find().then(rep => {
		res.send({
			data:rep,
			code:200
		})
	})
});
router.get('/shuiju',async function (req, res, next) {
	let {s_type}=req.query
	let search={}
	if(s_type){
		search.type=s_type
	}
	let total=await Renmodel.find().countDocuments()
	Renmodel.find(search).populate('type').then(rep => {
		res.send({
			data:rep,
			code:200,
			total
		})
	})
});
module.exports = router;
